// Copyright (C) 2005 Taylor L. Riché <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// 	$Id: CppMethods.java 282 2005-10-10 20:18:18Z richetl $	
//

import java.io.*;
import java.util.*;

class CppMethods
{
    public class Method
    {
	private LinkedList argList;
	private String name;
	private String type;
	public void setName(String n) {
	    name = n;
	}
	public String getName() {
	    return name;
	}
	public void setType(String t) {
	    type = t;
	}
	public String getType() {
	    return type;
	}
	public void setArgList(LinkedList l) {
	    argList = l;
	}
	public String getStringArgs() {
	    String retval = "";
	    Iterator args = argList.iterator();
	    int listSize = argList.size();
	    for(int i = 0; i < listSize; i++) {
		if(i > 0) {
		    retval += ", ";
		}
		Arg arg = (Arg)args.next();
		retval += arg.getType() + " " + arg.getName();
	    }
	    return retval;
	}
    }

    public class Arg
    {
	private String name;
	private String type;
	public void setName(String n) {
	    name = n;
	}
	public String getName() {
	    return name;
	}
	public void setType(String t) {
	    type = t;
	}
	public String getType() {
	    return type;
	}
	public String getDecl() {
	    return type + " " + name;
	}
    }

    private LinkedList methodList;

    public CppMethods() {
	methodList = new LinkedList();
    }

    public void print(PrintStream file) {
	Iterator methods = methodList.iterator();
	int listSize = methodList.size();
	for(int i = 0; i < listSize; i++) {
	    Method method = (Method)methods.next();
	    file.println("\t" + method.getType() + " " + method.getName()
			 + "(" + method.getStringArgs() + ");");
	}
    }

    public void printStubs(PrintStream file) {
	Iterator methods = methodList.iterator();
	int listSize = methodList.size();
	for(int i = 0; i < listSize; i++) {
	    Method method = (Method)methods.next();
	    file.println(method.getType() + "\n" + method.getName()
			 + "(" + method.getStringArgs() + ")");
	    file.println("{");
	    file.println("}");
	    file.println();
	}
    }

    public void addMethod(Method m) {
	methodList.addLast(m);
    }
}
